package cn.springmvc.controller;

import cn.springmvc.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: mayuanbao
 * @Date: 2018-11-26 10:26
 * @Description:
 */
@Controller
@RequestMapping(value = "/one")
public class oneController {
    @RequestMapping(value = "/say")
    public void say() {
        System.out.println("hello " + this);
    }

    @RequestMapping(value = "/save", method = RequestMethod.GET)
    public void save(String name, String age) {
        System.out.println("name is " + name + ", age is " + age);
    }

    @RequestMapping(value = "/save1/{nm}/{ag}")
    public void save1(@PathVariable("nm") String name,@PathVariable("ag") String age) {
        System.out.println("name is " + name + ", age is " + age);
    }

    @RequestMapping(value = "/json")
    @ResponseBody
    public Map<String, Object> json1(String name, String age) {
        User user = new User();
        user.setName(name);
        user.setAge(Integer.parseInt(age));
        Map<String,Object> map = new HashMap<>();
        map.put("user", user);
        map.put("status", 1);
        System.out.println(map);
        return map;
    }

}
